﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Wix.Aura.Common;
using Wix.Aura.Common.CustomTypes;
using Wix.Aura.UnitTests.Tools;

namespace Wix.Aura.UnitTests.Common {
	[TestFixture]
	public class ComponentSerialization {
		[SetUp]
		public void SetUp() {
			component = new Component();
		}

		Component component;

		[Test]
		public void EmptyComponent() {
			string expected = "<Component />";
			XmlAssert.AreEqual(expected, component);
		}

		[Test]
		public void AllAttributes() {
			string expected = @"<Component ComPlusFlags=""2"" Directory=""Directory"" DisableRegistryReflection=""yes"" DiskIdType=""9"" Feature=""Feature"" Guid=""00000000-0000-0000-0000-000000000000"" Id=""Identifier"" KeyPath=""yes"" Location=""local"" MultiInstance=""yes"" NeverOverride=""yes"" Permanent=""yes"" Shared=""yes"" SharedDllRefCount=""yes"" Transitive=""yes"" UninstallWhenSuperseded=""yes"" Win64=""yes"" />";

			component.ComPlusFlags = 2;
			component.Directory = "Directory";
			component.DisableRegistryReflection = YesNoType.Yes;
			component.DiskIdType = new DiskIdType(9);
			component.Feature = "Feature";
			component.Guid = new ComponentGuid(Guid.Empty);
			component.Id = "Identifier";
			component.KeyPath = YesNoType.Yes;
			component.Location = Location.Local;
			component.MultiInstance = YesNoType.Yes;
			component.NeverOverride = YesNoType.Yes;
			component.Permanent = YesNoType.Yes;
			component.Shared = YesNoType.Yes;
			component.SharedDllRefCount = YesNoType.Yes;
			component.Transitive = YesNoType.Yes;
			component.UninstallWhenSuperseded = YesNoType.Yes;
			component.Win64 = YesNoType.Yes;

			XmlAssert.AreEqual(expected, component);
		}

		[Test]
		public void ComponentWithClass() {
			component.Class.Add(new Class(Guid.Empty));
			XmlAssert.AreEqual(@"<Component><Class Id=""00000000-0000-0000-0000-000000000000"" /></Component>", component);
		}

		[Test]
		public void ComponentWithCondition() {
			component.Condition.Add(new ComponentCondition());
			XmlAssert.AreEqual(@"<Component><Condition /></Component>", component);
		}

		[Test]
		public void ComponentWithCopyFile() {
			component.CopyFile.Add(new CopyFile("copy"));
			XmlAssert.AreEqual(@"<Component><CopyFile Id=""copy"" /></Component>", component);
		}

		[Test]
		public void ComponentWithCreateFolder() {
			component.CreateFolder.Add(new CreateFolder());
			XmlAssert.AreEqual(@"<Component><CreateFolder /></Component>", component);
		}
	}
}
